<%@page import="custom.Activity"%>
<%@page import="custom.Quiz"%>
<%@page import="custom.Request"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title> <%= request.getParameter("name") %>'s profile </title>
</head>
<body>
	<%@ include file="header.jsp" %>
	<center><div style="width: 800px;" align="left">
		<div>
			<%
				String name = request.getParameter("name");
				int id =  User.getId(name);
				User user = (User) session.getAttribute("user");
			%>
			<p><%=User.getPictureNameHtml(id) %></p>
			<div style="display: inline;">
				<%
					if (!user.areYou(id)) {
						if(!user.isFriendWith(id) && !Request.requesSent(id, user.getId())){%>
							<div style="float: left; width: 13%;"><form action="RequestServlet" method="post">
								<input type="hidden" name="sender" value="<%= user.getId()%>" />
								<input type="hidden" name="reciver" value="<%= id%>"/>
								<input type="hidden" name="addOrRemove" value="add"/>
								<input type="submit" value="Add as Friend" />
							</form></div>
					<%	}else if(!Request.requesSent(id, user.getId())){ %>
							<div style="float: left; width: 19%;"><form action="RequestServlet" method="post">
								<input type="hidden" name="sender" value="<%= user.getId()%>" />
								<input type="hidden" name="reciver" value="<%= id%>"/>
								<input type="hidden" name="addOrRemove" value="rem"/>
								<input type="submit" value="Remove from Friends" />
							</form></div>
					<%	}%>
						<div style="float: left; width: 12%;"><input type="button" value="Conversation" ONCLICK="window.location.href='conversation.jsp?id=<%=id%>'" /></div>
						<%if(user.areYouAdmin() && User.isAdmin(id)){ %>
								<div style="float: left; width: 18%;"><form action="ChangeAdminStatusServlet" method="post">
									<input type="hidden" name="userToChange" value="<%=id%>" />
									<input type="submit" value="Remove from Admins" />
								</form></div>
						<%}else if(user.areYouAdmin()){ %>
								<div style="float: left; width: 10%;"><form action="ChangeAdminStatusServlet" method="post">
									<input type="hidden" name="userToChange" value="<%=id%>" />
									<input type="submit" value="Make Admin" />
								</form></div>
					<%	}%>
				<%	}%>
				
				<center><div style="width: 800px; background-color:rgb(256, 256, 230)">

					<div style="float: left; width: 69%; border-right:2px solid rgb(200,200,200); border-top:2px solid rgb(200,200,200); margin-right: 0.5%;" align="left">
						<div style="margin: 8px">
							<% 
								ArrayList<Activity> acti = User.getActivitiesOf(id);
								for(int i=0; i<acti.size(); i++){
									out.print("<p>"+acti.get(i).getHtml()+"</p>");
								}
								if(acti.size() == 0)
									out.print("<p>No Activities</p>");
							%>
						</div>
					</div>
					
								 
					<div style="float: left; width: 29%; border-left:2px solid rgb(200,200,200); border-top:2px solid rgb(200,200,200);" align="left">
						<div style="margin: 8px">
							<div style="font-style: italic; font-weight: 800;">Quizzes By <%=name%></div>
							
							<div id="Quizes By Me" align="left">
								<%
								Quiz[] hes= Quiz.fiveBy(id);
								int i;
								for(i=0; i<5; i++){
									if(hes[i]==null)
										break;
									out.print("<p>"+hes[i].getNameHtml()+"</p>");
								}
								if(i==0)
									out.print("<p>Hasn't created any quizzes yet</p>");
								%>
							</div>		
						</div>
					</div>
					
				</div></center>
				
			</div>
		</div>
	</div></center>
</body>
</html>